package utils

import (
	"regexp"
	"unicode/utf8"
)

// 校验用户名
func ValidateUsername(username string) bool {
	if utf8.RuneCountInString(username) < 3 || utf8.RuneCountInString(username) > 20 {
		return false
	}
	matched, _ := regexp.MatchString("^[a-zA-Z0-9]+$", username)
	return matched
}

// 校验密码
func ValidatePassword(password string) bool {
	if utf8.RuneCountInString(password) < 8 || utf8.RuneCountInString(password) > 20 {
		return false
	}
	matched, err := regexp.MatchString(`^[a-zA-Z0-9\W_]+$`, password)
	if err != nil {
		return false
	}
	return matched
}
